package com.ruibang.glass.equipment.controller;


import com.alibaba.nacos.common.utils.CollectionUtils;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.AccidentRectification;
import com.ruibang.glass.equipment.service.AccidentRectificationService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *事故整改台账接口服务
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */

@RestController
@RequestMapping("/api/equipment/accident/rectification")
@Api(value = "事故整改台账")
public class AccidentRectificationController {
    @Autowired
    private AccidentRectificationService accidentRectificationService;

    @PostMapping("list")
    @ApiOperation(value = "检修工作单列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody DeviceAllPageReq deviceAllPageReq) {
        return ResultBody.success(accidentRectificationService.queryPage(deviceAllPageReq));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addChild(@RequestBody AccidentRectification accidentRegister) {
        return ResultBody.success(accidentRectificationService.updateOrAddById(accidentRegister));
    }

    @PostMapping("deleteAll")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody AccidentRectification accidentRegister) {
        if (CollectionUtils.isNotEmpty(accidentRegister.getIds())) {
//            accidentRectificationService.removeBatchByIds(accidentRegister.getIds());
            accidentRectificationService.lambdaUpdate().set(AccidentRectification::getIsDelete, Constants.ONE_STR).in(AccidentRectification::getId,accidentRegister.getIds()).update();
        }
        if (StringUtils.isNoneBlank(accidentRegister.getId())) {
//            accidentRectificationService.removeById(accidentRegister.getId());
            accidentRectificationService.lambdaUpdate().set(AccidentRectification::getIsDelete, Constants.ONE_STR).eq(AccidentRectification::getId,accidentRegister.getId()).update();
        }


        return ResultBody.success(accidentRectificationService.removeById(accidentRegister.getId()));
    }


    @PostMapping("getOne")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getOne(@RequestBody AccidentRectification accidentRegister) {
        return ResultBody.success(accidentRectificationService.getById(accidentRegister.getId()));
    }


}
